function[pictures] = loadPictures(imageClass)
% Loads all pictures of a certain class into a cell array.
%
%   INPUT
%   imageClass..string specifying the image class.
%   OUTPUT
%   pictures....The cell array containing all test images of the given
%               class. The returned images are already in binary format and
%               sorted by their number.
%
% The code is an adapted version of the given code in the exercise
% instructions.
    
    D = dir(['Testbilder/' imageClass '*.gif']);
    count = size(D, 1);
    I = cell(count, 1);
    % sort the images by their number, so that one can refer to the exact
    % image by the id (position) of the picture in the returned cell array
    % that means e.g. picture bat-5.gif will be the 5th picture in the
    % cell array
    numbers = zeros(1, count);
    from = size(imageClass, 2) + 2;
    for i = 1 : count
        to = size(D(i).name, 2) - 4;
        numbers(i) = str2double(D(i).name(from : to));
    end
    % notNeeded not replaced by ~ for downward compatibility reasons
    [notNeeded, newOrder] = sort(numbers);
    for i = 1 : count
        I_temp = imread(['Testbilder/' D(newOrder(i)).name]);
        I{i} = im2bw(I_temp, graythresh(I_temp));
    end
    pictures = I;
end
